//
//  UIImage+Common.m
//  ACLiteAVUISDK
//
//  Created by 冯琰琰 on 2021/3/29.
//

#import "UIImage+Common.h"

@implementation UIImage (Common)
+ (instancetype)imageWithName:(NSString *)name bundle:(NSString *)bundleName targetClass:(Class)targetClass{
    NSInteger scale = [[UIScreen mainScreen] scale];
    NSBundle *curB = [NSBundle bundleForClass:targetClass];
    NSString *imgName = [NSString stringWithFormat:@"%@@%zdx.png", name,scale];
    NSString *dir = [NSString stringWithFormat:@"%@.bundle",bundleName];
    NSString *path = [curB pathForResource:imgName ofType:nil inDirectory:dir];
    if ([UIImage imageWithContentsOfFile:path]) {
        return [UIImage imageWithContentsOfFile:path];
    }else{
        return [UIImage imageWithContentsOfFile:[curB pathForResource:[name stringByAppendingString:@".png"] ofType:nil inDirectory:dir]];
    }
}
@end
